<template>
	<view class="pagebox flex-center">
		<view class="loginbox flex-column-center">
			<image src="../../static/logo.png" mode="aspectFill" class="logo"></image>
			<text class="logotext">麦丝儿客服</text>
			
			<div class="inputbox flex-row-center mb20">
				<input class="input flex1 ml30 flex-row-center" type="text" maxlength="20" placeholder="请输入账号" placeholder-style="color:#c7c8c9;font-size:28rpx;" v-model="form.uname"/>
			</div>
			<div class="inputbox flex-row-center mb20">
				<input class="input flex1 ml30 flex-row-center" type="text" maxlength="20" placeholder="请输入密码" placeholder-style="color:#c7c8c9;font-size:28rpx;" v-model="form.pass"/>
			</div>
			<button class="button base-bg w-color" open-type="getUserInfo" :disabled="disabled" @click="loginsub">登录</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				disabled: false,
				form: {
					"uname": "",
					"pass": ""
				},
			};
		},
		onLoad() {
		},
		methods: {
			loginsub(){
				if(!this.form.uname){
					this.$c.Toast('请输入账号！');
					return
				}
				if(!this.form.pass){
					this.$c.Toast('请输入密码！！');
					return
				}
				uni.setStorageSync('loginData',this.form)
				this.login('customerservice/login',this.form)
			},
			login(url,f){
				this.disabled = true
				this.$reQuest.post(url,f,{token: false},).then(res=>{
						if(res.success){
							this.$c.setToken(res.msg.token);
							let user_ = this.$c.getUser()?JSON.parse(this.$c.getUser()):{};
							const user = {
								...user_,
								...res.msg,
							}
							this.$c.setUser(JSON.stringify(user));
							this.$c.Toast('登录成功');
							this.$c.go_url('/pages/customer/index','reLaunch');
							
						}else{
							this.disabled = false
							this.$c.Toast(res.err);
						}
				}).catch(err=>{this.disabled = false})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.pagebox{
		width: 100vw;height: 100vh;background: linear-gradient( 86deg, #E2EEFF 0%, #EAECFF 100%);
		.loginbox{
			width: 690rpx;height: auto;min-height: 300rpx;
			.logo{
				width: 240rpx;height: 240rpx;border-radius: 240rpx;overflow: hidden;
			}
			.logotext{font-size: 32rpx;font-weight: bold;margin-top: 20rpx;margin-bottom: 100rpx;}
			.button{
				width: 100%;height: 100rpx;border-radius: 100rpx;text-align: center;line-height: 100rpx;font-size: 26rpx;
			}
			.inputbox{
				width: 100%;height: 100rpx;border-radius: 100rpx;background: #fff;font-size: 32rpx;
			}
			.desc{font-size: 22rpx;color: #999;margin-top: 20rpx;}
			
			.xieyi{font-size: 24rpx;}
		}
	}
</style>
